﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.DAL;

public partial class GateService_Home_View_Count : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Response.ContentType = "text/xml";
            Response.Clear();

            string header = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><result error=\"{0}\">{1}</result>";
            try
            {
                HomeViewCountBLL bll = new HomeViewCountBLL();
                string param = Request.Params["op"];
                string sLang = Request.Params["lang"];
                if (string.IsNullOrEmpty(sLang)) throw new ArgumentNullException("lang");
                string output = string.Empty;

                int langID = int.Parse(sLang);
                if (param == "set")
                {
                    bll.Update(langID);
                    //bll.getCount();
                    int currCount = bll.getCount();
                    Application["Application_Home_View_Count"] = currCount;
                    output = string.Format(header, "", currCount);
                }
                else if (param == "get")
                {
                    object obj = Application["Application_Home_View_Count"];
                    if (obj != null)
                    {
                        output = string.Format(header, "", obj);
                    }
                    else
                    {
                        int currCount = bll.getCount();
                        Application["Application_Home_View_Count"] = currCount;
                        output = string.Format(header, "", currCount);
                    }
                }

                Response.Write(output);
            }
            catch (Exception ee)
            {
                Response.Write(string.Format(header, ee.Message, -1));
            }
        }
    }
}